Create a Matlab wrapper for the com.sun.net.httpserver.HttpExchange java object. This object is used when a webservice is called to retrieve request info, such as the data and headers and to prepare the message to be returned. The data sent by the client are stored as redundant data in this constructor.
Create a Matlab wrapper for the com.sun.net.httpserver.HttpExchange java object. This object is used when a webservice is called to retrieve request info, such as the data and headers and to prepare the message to be returned. The data sent by the client are stored as redundant data in this constructor.
obj = HttpExchange(httpExchange) obj = HttpExchange(charString)
httpExchange | sun.net.httpserver.HttpExchangeImpl |
obj | modelit.webserver.HttpExchange | Documentation for modelit.web.server.HttpExchange/HttpExchange doc modelit.web.server.HttpExchange |
Default callback for webservice.
http_callback(obj,port, callbackFcn) http_callback(obj,port, requestName, callbackFcnList)
obj | modelit.web.server.HttpExchange | |
port | int | callbackFcn: <@(event, port) => [msg,response,content_type]> function with signature: [msg,response,content_type]=fp_callback(event,port) |
requestName | string | Refers to field in http-get string that corresponds to "callbackFcnList.name". By convention either: empty ==> skip search char ==> retrieve parameter and check callbackFcnList.name for match function pointer ==> check callbackFcnList.name for match with requestName(obj) |
callbackFcnList | struct[] | struct array with fields +----name +----action |
No output. EXAMPLE (1): actions = struct('name','traveltime','action',@do_tileViewer_spt); actions(end+1) = struct('name','speed', 'action',@do_tileViewer_ndw); server = modelit.web.server.Server(hostname, port, @(e)http_callback(e, port,'maptype',actions)); In this example the "maptype" parameter in queries will be matched with the "name" parameters in the struct array "actions". Note that a better way to divert calls to different callback is to use the "context" property, as in the next example. EXAMPLE (2): server = modelit.web.server.Server(hostname, port) addContext(obj, '/spt', @(e)http_callback(e, port,@do_tileViewer_spt) ) addContext(obj, '/spt', @(e)http_callback(e, port,@do_tileViewer_ndw) )
Send the response and statuscode to the requester.
send(obj, statuscode, response)
obj | modelit.webserver.HttpExchange | |
statuscode | number | (optional, default: 200) http statuscode, e.g. 200 ok, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status |
response | modelit.webserver.HttpExchange | The response data (optional, default: '') |
No output.
Returns the value for a given query parameter.
value = getQueryValue(obj, name, default) value = getQueryValue(obj, name, default,query)
obj | modelit.webserver.HttpExchange | |
name | string | name of attribute to retrieve |
default | any | Default value for this parameter, also used to convert the value to the required format. The query values are always stored as strings. |
query | struct array | Preprocessed value obtained with "query=getQuery(obj)" |
value | any | The value for the given query name, converted to the same format as the default value. |
Returns the query parameters of the http request. (The parameters after the ? in the URL).
value = getQuery(obj)
obj | modelit.webserver.HttpExchange |
value | struct[] | One struct per parameter, value pair fields: -name, -value |
Convert httpget string to structure with input arguments. Take care of name completion; Supply default arguments; Cast parameters to correct type.
obj | modelit.web.server.HttpExchange | |
defopt | any | Structure with default parameters. deftop.NAME=VALUE implies that VALUE is default parameter value for NAME. |
varargin | any |
opt | struct | structure with options. |
errorMsg | string | informative textual feedback in case of syntax error |
qstr | string | text of queary after urldecode |
NOTES | any | - Current utility reads "simple" hhtp get strings, meaning that name/value pairs are read from input string. Values must be scalar and of type CHAR, LOGICAL, NUMERIC. LOGICAL values must be supplied as "0" or "1" - An equivalent function httpget2struct exists as well. This can be used while debugging callback functions from example query strings. |
Returns the query parameters of the http request as a string.
value = getQueryString(obj)
obj | modelit.webserver.HttpExchange |
value | string | With name value pairs |
Equivalent to getQueryString but returns requestBody if requestQuery is empty.
value = char(obj)
obj | modelit.webserver.HttpExchange |
value | string | With the query string or the requestBody if the requestQuery is empty. |
Add a header with a value to the response.
obj = HttpExchange(httpExchange)
obj | modelit.webserver.HttpExchange | |
varargin | containers.Map|cellstr | with param, value pairs. |
No output.
addResponseHeader(obj, {'contenttype', 'text/html'})
Returns the decoded path component of this URI.
value = getPath(obj)
obj | modelit.webserver.HttpExchange |
value | string | The path of the the URI. |
Returns the response headers.
value = getResponseHeaders(obj)
obj | modelit.webserver.HttpExchange |
value | containers.Map<string, string | Map with the header name, value pairs. Multiple values for a single name or concatenate in a ,-separated list, e.g. "gzip, deflate, br" |
Return the data sent with the http request.
value = getRequestBody(obj)
obj | modelit.webserver.HttpExchange |
value | int8[] | The data as a bytearray (int8) as it was sent with the http request. |
Get the request headers.
value = getRequestHeaders(obj)
obj | modelit.webserver.HttpExchange |
value | containers.Map<string, string | Map with the header name, value pairs. Multiple values for a single name or concatenate in a ,-separated list, e.g. "gzip, deflate, br" |
Returns the http request method.
value = getRequestMethod(obj)
obj | any | <modelit.webserver.HttpExchange> |
value | string | The http request method. e.g. Post or Get. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods |
Returns the local address in the form hostname:port.
value = getRemoteAddress(obj)
obj | modelit.webserver.HttpExchange |
value | string | The local address: hostname:port |
Returns the remote address in the form hostname:port.
value = getRemoteAddress(obj)
obj | modelit.webserver.HttpExchange |
value | string | The remote address: hostname:port |
Returns the protocol in the form protocol/majorVersion.minorVersion.
value = getProtocol(obj)
obj | modelit.webserver.HttpExchange |
value | string | protocol/majorVersion.minorVersion. e.g. HTTP/1.1 |
Returns the HttpPrincipal or '' if no authentication is used. If an authenticator is set on the HttpContext that owns this exchange, then this method will return the HttpPrincipal that represents the authenticated user for this HttpExchange.
value = getPrincipal(obj)
obj | modelit.webserver.HttpExchange |
value | string | the name of the HttpPrincipal or '' if no authentication was used. |
event | any | http event object |
requestName | any | 1 of the following empty string this will result in f_action=1 and errormsg='' string this will read property <string> from event as request_type and then find f_action by matching request_type with callbackFcnList.name function pointer this will result in request_type=requestName(event); and then find f_action by matching request_type with callbackFcnList.name |
callbackFcnList | any | if requestName is nonempty. callbackFcnList.name is matched with requesttype. |
errormsg | any | Debug message (will be displayed on console) |
f_action | any | index in struct array "callbackFcnList" |